home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / comm / net / ARemote1_00B.lha / ARemote / source / aremotedebug.c < prev    next >
C/C++ Source or Header  |  1997-04-27  |  7KB  |  196 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #include <dos/dos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. #include <clib/AMarquee_protos.h>
  11. #include <devices/inputevent.h>
  12.  
  13. #include <pragmas/AMarquee_pragmas.h>
  14.  
  15. struct Library * AMarqueeBase = NULL;
  16. struct QSession * session     = NULL;
  17. FILE * fTest = NULL;
  18.  
  19. /* Takes user input until blank line is typed */
  20. void ProcessDebugCommands(struct QSession * session)
  21. {
  22.   while(1)
  23.   {
  24.    char debugline[500] = "\0\0\0\0\0\0\0\0";
  25.    char * keyword, * data;
  26.    ULONG dataLen = 0L;
  27.    LONG res;
  28.    
  29.    printf("Enter your debug command now: "); fflush(stdout);
  30.    gets(debugline);
  31.   
  32.    keyword = &debugline[2];
  33.    if (data = strchr(keyword,'='))
  34.    {
  35.      *data = '\0';  /* terminate the keyword */
  36.      data++;
  37.      dataLen = strlen(data)+1;
  38.    }
  39.    switch((int)(debugline[0]))
  40.    {
  41.      case '\0': res=QGo(session,0L);                           break;
  42.      case 'A':  res=QSetMessageAccessOp(session, keyword, -1); break;
  43.      case 'm':  res=QMessageOp(session, keyword, data, dataLen); break;
  44.      case 'a':  res=QSetAccessOp(session, keyword);          break;
  45.      case 's':  res=QSetOp(session, keyword, data, dataLen); break;
  46.      case 'S':  res=QStreamOp(session, keyword, data, dataLen); break;
  47.      case 'r':  res=QRenameOp(session, keyword, data);       break;
  48.      case 'D':  res=QDebugOp(session, keyword);              break;
  49.      case 'g':  res=QGetOp(session, keyword, -1);            break;
  50.      case 'd':  res=QDeleteOp(session, keyword);             break;
  51.      case 'i':  res=QInfoOp(session);                        break;
  52.      case 'c':  res=QSubscribeOp(session, keyword, -1);      break;
  53.      case 'k':  res=QClearSubscriptionsOp(session,atoi(keyword)); break;
  54.      case 'p':  res=QPingOp(session);                        break;
  55.      default:   printf("Command code %c was not recognized.\n",debugline[0]); break;
  56.    }
  57.    printf("(Op result was %i)\n",res);
  58.    if (debugline[0] == '\0') return;
  59.   }
  60. }
  61.  
  62.  
  63. void CleanExit(void)
  64. {
  65. printf("\nCleaning up...\n");
  66.   if (fTest) fclose(fTest);
  67.   if (session)      QFreeSession(session);        /* This MUST be done before we close the library! */
  68.   if (AMarqueeBase) CloseLibrary(AMarqueeBase);  
  69.   printf("All done.\n");
  70. }
  71.  
  72. /* Main program */
  73. int main(int argc, char ** argv)
  74. {
  75.   char * connectTo, * progName;
  76.   int port;
  77.  
  78.   fTest = fopen("ie.bin","wb");    
  79.   if (fTest == NULL) 
  80.   {
  81.     printf("Couldn't open test file ie.bin\n");
  82.     exit(0);
  83.   }
  84.   
  85.   printf("Usage Note:  AMarqueeDebug [hostname=localhost] [myname=debug] [port=2957]\n");  
  86.   atexit(CleanExit);
  87.   
  88.   connectTo = (argc>1) ? argv[1] : "localhost";
  89.   progName  = (argc>2) ? argv[2] : "ARemote";
  90.   port      = (argc>3) ? atoi(argv[3]) : 20000;
  91.  
  92.   if ((AMarqueeBase = OpenLibrary("amarquee.library",41L)) == NULL)
  93.   {
  94.     printf("Couldn't open amarquee.library v41!\n");
  95.     exit(RETURN_ERROR);
  96.   }
  97.   printf("Connecting to %s:%i\n",connectTo, port);
  98.  
  99. #ifdef ASYNC_CONNECT
  100.   if ((session = QNewSessionAsync(connectTo, port, progName)) == NULL)
  101.   {
  102.     printf("Couldn't connect to server %s:%i\n",connectTo, port);
  103.     exit(RETURN_WARN);
  104.   }
  105. #else
  106.   if ((session = QNewSession(connectTo, port, progName)) == NULL)
  107.   {
  108.     printf("Couldn't connect to server %s:%i\n",connectTo, port);
  109.     exit(RETURN_WARN);
  110.   }
  111. #endif
  112.  
  113.   printf("Connected to server %s:%i\n",connectTo, port);
  114.  
  115.   /* Setup some sample data */
  116. /*
  117.   (void)QSetOp(session, "sampledata",             "Kids",    5);
  118.   (void)QSetOp(session, "sampledata/Jeremy",      "1",       2);
  119.   (void)QSetOp(session, "sampledata/Joanna",      "2",       2);
  120.   (void)QSetOp(session, "sampledata/Joanna/nerd", "yep! :)", 8);
  121.   (void)QSetOp(session, "sampledata/Joellen",     "3",       2);
  122.   (void)QSetOp(session, "sampledata/Charcoal",    "Kitty!",  7);
  123.   (void)QGo(session, 0L);
  124. */
  125.  
  126.   printf("Commands are:\n");
  127.   printf("\n");
  128.   printf("a wildhostpath   Access control (default is /#?/#?)\n");
  129.   printf("A wildhostpath   Access control for incoming messages (default in no access)\n");
  130.   printf("m hosts=data     Send an active message to hosts\n");
  131.   printf("s path=data      Set data node value\n");
  132.   printf("S path=data      Stream data node value\n");
  133.   printf("r path=newlabel  Rename data node\n");
  134.   printf("D debugstring    Send debug string\n");
  135.   printf("g wildpath       Get a node or nodes\n");
  136.   printf("c wildpath       Subscribe to a node or nodes\n");
  137.   printf("k opID           Klear subscriptions (by id or 0 for all)\n");
  138.   printf("d wildpath       Delete a node or nodes\n");
  139.   printf("i                Request info packet\n");
  140.   printf("p                Request ping packet\n");
  141.   printf("<enter>          Send accumulated transactions (GO!!)\n");
  142.   printf("\n");
  143.   printf("Press CTRL-F to enter commands, or CTRL-C to quit\n");
  144.   
  145.   while(1)
  146.   {
  147.     struct QMessage * qMsg;
  148.     ULONG signals = (1L << session->qMsgPort->mp_SigBit) | (SIGBREAKF_CTRL_C) | (SIGBREAKF_CTRL_F);
  149.  
  150.     /* Wait for next message from the server */
  151.     signals = Wait(signals);
  152.     
  153.     if (signals & (1L << session->qMsgPort->mp_SigBit))
  154.     {
  155.       while(qMsg = (struct QMessage *) GetMsg(session->qMsgPort))
  156.       {
  157.         struct InputEvent * ie = (struct InputEvent *) qMsg->qm_Data;
  158.        
  159.         if ((ie)&&(qMsg->qm_DataLen == sizeof(struct InputEvent)))
  160.         {
  161. #ifdef DEBUG_ME
  162.           printf("-----\n");
  163.           printf("ie_NextEvent = %p\n",ie->ie_NextEvent);
  164.           printf("class = %x, subClass = %x, code = %x(%c), qual = %x\n",
  165.             ie->ie_Class, ie->ie_SubClass, ie->ie_Code, ie->ie_Code, ie->ie_Qualifier);
  166.           switch(ie->ie_Class)
  167.           {
  168.             case IECLASS_RAWMOUSE: case IECLASS_POINTERPOS:
  169.               printf("ie_x = %i, ie_y = %i\n",ie->ie_position.ie_xy.ie_x, ie->ie_position.ie_xy.ie_y);
  170.               break;
  171.               
  172.             case IECLASS_RAWKEY:
  173.               printf("ie_pdC1 = %i, ie_pdQ1 = %i, ie_pdC2 = %i, ie_pdQ2 = %i\n",
  174.                 ie->ie_position.ie_dead.ie_prev1DownCode,
  175.                 ie->ie_position.ie_dead.ie_prev1DownQual,
  176.                 ie->ie_position.ie_dead.ie_prev2DownCode,
  177.                 ie->ie_position.ie_dead.ie_prev2DownQual);
  178.               break;
  179.           }
  180.           printf("ie_addr = %p\n",ie->ie_position.ie_addr);
  181.           printf("ie_TimeStamp = %lu\n",ie->ie_TimeStamp);          
  182. #endif
  183.           printf("writing msg class %x subclass %x\n",ie->ie_Class, ie->ie_SubClass);
  184.           fwrite(ie, 1, sizeof(struct InputEvent), fTest);
  185.         }
  186.         else printf("Bad inputEvent %p %i\n",ie, qMsg->qm_DataLen);
  187.         
  188.         FreeQMessage(session, qMsg);
  189.       }
  190.     }
  191.     if (signals & SIGBREAKF_CTRL_F) ProcessDebugCommands(session);
  192.     if (signals & SIGBREAKF_CTRL_C) break;  /* Quit if CTRL-C pressed */
  193.   }
  194.   /* CleanExit() called here! */
  195. }
  196.